import { RootResponse, ListResponse, eventTypesData, zbListRoot } from './type'
import { get, post } from '@/utils/methods'

/**
 * 获取仪表盘总览数据
 * @returns Promise<RootResponse>
 */
export function fetchDashboardOverview(): Promise<RootResponse> {
    return get('/index/data')
}

/**
 * 获取事件列表（以 FormData 方式提交）
 * @param eventType 清单类型（必传）
 * @param page 页码，默认 1
 * @param pageSize 每页数量，默认 20
 * @returns Promise<ListResponse>
 */
export function fetchEventList(
    eventType: string,
    page: number = 1,
    pageSize: number = 2
): Promise<ListResponse> {
    const payload = {
        eventType: eventType,
        Page: page,
        PageSize: pageSize,
    };

    return post('/index/eventList', payload,);
}

export function eventTypes(): Promise<eventTypesData> {
    return get('/index/eventTypes')
}

export function eventClose(data: { id: any[] }): Promise<RootResponse> {
    return post(`/index/eventClose`, data)
}
export function eventDel(data: { id: any[] }): Promise<RootResponse> {
    return post(`/index/eventDel`, data)
}

export function DigitalEmployee(): Promise<RootResponse> {
    return get(`/index/DigitalEmployee/agents`)
}

export function DigitalEmployeelogs(data: {
    workflow?: string;   // 事件类型，可选
    logStatus?: number | ""; // 日志状态，可选
    name?: string;        // 名称搜索，可选
    Page?: number;        // 页码
    PageSize?: number;    // 每页条数
}): Promise<ListResponse> {
    // 去掉空值字段（防止 '' 或 undefined 传给后端）
    const payload: any = {};
    Object.keys(data).forEach(key => {
        const value = (data as any)[key];
        if (value !== "" && value !== undefined && value !== null) {
            payload[key] = value;
        }
    });

    return post(`/index/DigitalEmployee/logs`, payload);
}


export function logsClose(data: { id: any[] }): Promise<RootResponse> {
    return post(`/index/DigitalEmployee/logsClose`, data)
}


export function zbList(): Promise<zbListRoot> {
    return get(`/index/zbList`)
}
export function zbChart(data: { type: string, zbName: string }) {
    return post(`/index/zbChart`, data)
}




